package com.wyh.service.serviceImpl.g3serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wyh.domain.po.g3po.G3Formula;
import com.wyh.domain.vo.g3vo.FomualVO;
import com.wyh.mapper.g3mapper.FormulaMapper;
import com.wyh.service.g3service.FormulaService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class FormulaServiceImpl extends ServiceImpl<FormulaMapper, G3Formula> implements FormulaService {

    @Autowired
    FormulaMapper formulaMapper;


    @Override
    public List<G3Formula> findFormulaByType(Integer typeid) {
        QueryWrapper<G3Formula> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type",typeid);
        List<G3Formula> g3Formulas = formulaMapper.selectList(queryWrapper);
        return g3Formulas;
    }

    @Override
    public FomualVO findFormula(Integer typeId,Integer current,Integer size) {
        FomualVO fomualVO = new FomualVO();
        QueryWrapper<G3Formula> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(typeId!=null,"type", typeId);
        IPage page = new Page(current,size);
        IPage result = formulaMapper.selectPage(page, queryWrapper);
        long total = result.getTotal();
        List<G3Formula> records = (List<G3Formula>) result.getRecords();

        fomualVO.setTotal(total);
        fomualVO.setFormulas(records);

        return fomualVO;
    }

}
